package com.hl.springboot4.filterintcepter;

import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

/**
 * @ClassName CorsConfig
 * @Description TODO
 * @Author libowen
 * @Date 2025年03月06日 10:45
 * @Version 1.0
 */
@Configuration
public class CorsConfig implements WebMvcConfigurer {
    // 跨域处理
    @Override
    public void addCorsMappings(CorsRegistry registry) {
        registry.addMapping("/**")  // 允许跨域的路径
                .allowedOrigins("*")   // 允许跨域的请求来源
                .allowedMethods("GET", "POST", "PUT", "DELETE") // 允许的请求方法
                .allowedHeaders("*")    // 允许的请求头
                .maxAge(3600);  // 预检请求的缓存时间（秒）
    }

    @Override
    public void addInterceptors(InterceptorRegistry registry) {
        registry.addInterceptor(new MyIncepter())   // 拦截器
                .addPathPatterns("/**")  // 拦截的路径
                .excludePathPatterns("/user/**"); //  排除的路径
//        registry.addInterceptor(new MyIncepter2())
//                .addPathPatterns("/article/*");

    }
}
